#include "game.h"
#include <stdio.h>
#include <Windows.h>
#include <conio.h>
#include "pot.h"
#include "handyConsoleFunctions.h"
#include "gamePhase.h"
#include "mainMenuPhase.h"
#include "updatePotPhase.h"
#include "actionSelectionPhase.h"
#include "resolutionPhase.h"
#include "outcomePhase.h"
//Constructor
Game::Game()
{
	state = MAIN_MENU;
	running = true;
	input = NULL;
	phases[MAIN_MENU] = new MainMenuPhase("mainmenu.txt", this);
	phases[NEW_POT]= new UpdatePotPhase("newPot.txt", this);
	phases[ACTION_SELECTION] = new ActionSelectionPhase(this);
	phases[RESOLUTION] = new ResolutionPhase(this);
	phases[OUTCOME] = new OutcomePhase(this);
	phases[SPLIT_THE_POT] = phases[NEW_POT];	//This should let us work through the updatePotPhase, but give us an indicator that we are in a differentPhase
	thePlayers[0].name = "Mr. Black";
	thePlayers[1].name = "Huggy";
	thePlayers[2].name = "Lotus";
	thePlayers[3].name = "Igor";
	thePlayers[4].name = "El Toro";
	thePlayers[5].name = "Tino";
	potShuffled = false;
}
//Deconstructor
Game::~Game()
{
	delete phases[MAIN_MENU];
	phases[MAIN_MENU] = NULL;
	delete phases[NEW_POT];
	phases[NEW_POT] = NULL;
	delete phases[ACTION_SELECTION];
	phases[ACTION_SELECTION] = NULL;
	delete phases[RESOLUTION];
	phases[RESOLUTION] = NULL;
	delete phases[OUTCOME];
	phases[OUTCOME] = NULL;
}

//Game Loops functions
void Game::handleInput(int a_input)
{
	input = a_input;
}

void Game::update(int timePassed)
{
	if (!potShuffled)
	{
		phases[NEW_POT]->update(timePassed);
		potShuffled = true;
	}
	phases[state]->getInput(input);
	phases[state]->update(timePassed);
	input = 0;
}

void Game::draw()
{
	gotoxy(0,0);
	phases[state]->draw();
}

//Accessors
bool Game::isRunning() 
{
	return running;
}